﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
//using MySql.Data.MySqlClient;
using dbcntn;

namespace Campus.Main.Basic
{
    public partial class BasicUserForm : Form
    {
        /*protected MySqlDataAdapter adapter;        
        protected MySqlConnection MySqlConnection;
        protected MySqlCommand MySqlCommand;
        protected MySqlDataReader Reader;*/
        protected ConnectionToDb aDb;

        public BasicUserForm()
        {
            MaximizeBox = false;
            InitializeComponent();
            aDb = new ConnectionToDb(Helper.ConnectionString);
            label1.Text = aDb.SelectUserName(Helper.SId);
        }

        private int CountBAll(string studentId)
        {
            string ort = aDb.SelectField("SELECT GOrt FROM EOgrOrtalamaReplYurt WHERE Numara LIKE('" + studentId + "')");
            string handicap = aDb.SelectField("onmaintable", "handicap_id", "student_id", studentId);
            string place = aDb.SelectField("onmaintable", "place_id", "student_id", studentId);
            string cource = aDb.SelectField("onmaintable", "cource_id", "student_id", studentId);
            string dhandicap = aDb.SelectField("onmaintable", "dad_handicap_id", "student_id", studentId);
            string mhandicap = aDb.SelectField("onmaintable", "mom_handicap_id", "student_id", studentId);
            string parentstate = aDb.SelectField("onmaintable", "parent_state", "student_id", studentId);
            string kardes = aDb.SelectField("onmaintable", "studyfamilycount", "student_id", studentId); 
            string puanortalama =aDb.SelectField("SELECT id FROM puanortalama WHERE max_value>=" + ort + " and min_value<=" +ort);
            string hazirlikball_id = aDb.SelectField("onmaintable", "hazirlikball_id", "student_id", studentId);
            var tableName = new string[2,9];

            tableName[0, 0] = "cource";
            tableName[1, 0] = cource;
            tableName[0, 1] = "place";
            tableName[1, 1] = place;
            tableName[0, 2] = "parentstate";
            tableName[1, 2] = parentstate;
            tableName[0, 3] = "studenthandicap";
            tableName[1, 3] = handicap;
            tableName[0, 4] = "parenthandicap";
            tableName[1, 4] = dhandicap;
            tableName[0, 5] = "parenthandicap";
            tableName[1, 5] = mhandicap;
            tableName[0, 6] = "kardes";
            tableName[1, 6] = kardes;
            tableName[0, 7] = "puanortalama";
            tableName[1, 7] = puanortalama;
            tableName[0, 8] = "hazirlik";
            tableName[1, 8] = hazirlikball_id;

            int ball = aDb.SelectTable(tableName);
            ball += Int32.Parse(aDb.SelectField("select ceza from onmaintable where student_id like('" + studentId +"')"));
            ball += Int32.Parse(aDb.SelectField("select a.description from odul a,onmaintable b where b.odul_id=a.id and b.student_id like('"+studentId+"')"));
            return ball;
        }



        protected virtual void button1_Click(object sender, EventArgs e)
        {
            var k=new Kayit();
            if (radioButton1.Checked)
            {
                k.pol = 1;
                k.cmb_sex.SelectedValue = 1;
            }
            if (radioButton2.Checked)
            {
                k.pol = 2;
                k.cmb_sex.SelectedValue = 2;
            }
            k.ShowDialog();

        }

        private void оПрграммеToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About about = new About();
            about.StartPosition = FormStartPosition.CenterScreen;
            about.ShowDialog();
        }

        protected virtual void button2_Click(object sender, EventArgs e)
        {
            KKayit f=new KKayit();
            if (radioButton3.Checked)
            {
                f.pol = 1;
            }
            if (radioButton4.Checked)
            {
                f.pol = 2;
            }
            f.ShowDialog();
        }

        protected virtual void btn_allListO_Click(object sender, EventArgs e)
        {
            BolumInsertForm f=new BolumInsertForm();
            f.ShowDialog();
        }

        protected virtual void btn_search_Click(object sender, EventArgs e)
        {
            SearchForm f=new SearchForm();
            f.ShowDialog();
        }

        protected virtual void btn_setting_Click(object sender, EventArgs e)
        {
            SettingMainForm f=new SettingMainForm();
            f.ShowDialog();
        }

        protected virtual void btn_ball_Click(object sender, EventArgs e)
        {
            var f=new BallSystem.BallSystem();
            f.ShowDialog();
        }

        protected virtual void btn_allListK_Click(object sender, EventArgs e)
        {
            AllListK allListK=new AllListK();
            allListK.ShowDialog();
        }

        protected virtual void button1_Click_1(object sender, EventArgs e)
        {
            Report1 f=new Report1();
            f.ShowDialog();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            ImzaCizelgesi f=new ImzaCizelgesi();
            f.ShowDialog();
        }

        private void btn_arsiv_Click(object sender, EventArgs e)
        {
            KayitSilderenler f=new KayitSilderenler();
            f.ShowDialog();
        }

        private void BasicUserForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                btn_onkayit.Enabled = true;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                btn_onkayit.Enabled = true;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                btn_kesinkayit.Enabled = true;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                btn_kesinkayit.Enabled = true;
            }
        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton5.Checked)
            {
                button1.Enabled = true;
            }
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton6.Checked)
            {
                button1.Enabled = true;
            }
        }

        private void button1_Click_2(object sender, EventArgs e)
        {
            Devamsizlik f=new Devamsizlik();
            if (radioButton5.Checked)
                f.Pol = 1;
            if (radioButton6.Checked)
                f.Pol = 2;
            f.ShowDialog();
        }

        protected virtual void ortalamaVePuanlariYenilemekToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ortalama ve puanlari yenilemek istiyormusunuz???", "Dikkat", MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                var temp = aDb.SelectStudentId();
                aDb.Call("CALL autodeletedublicates");
                aDb.UpdateOrtalama();
                foreach (var s in temp)
                {
                    aDb.UpdateMainTable("ball", CountBAll(s), s);
                }
            }
        }

        private void помощьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process.Start(Application.StartupPath + "\\Help.docx");
        }
    }
}
